package com.yb.xczx.cloud.auth.bean;

import com.yb.core.enums.LoginTypeEnum;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/18 13:30
 * FileName: XczxTokenAuthenticationToken
 * Description:
 */



public class XczxUserLoginCodeAuthenticationToken extends XczxAbstractAuthenticationToken {

    private String loginCode;//请求token

    private String accessToken; //访问token
    /**
     * Creates a token with the supplied array of authorities.
     *
     * @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
     *                    represented by this authentication object.
     */
    public XczxUserLoginCodeAuthenticationToken(XczxSysUser xczxSysUser, String  loginCode, String accessToken, Collection<? extends GrantedAuthority> authorities) {
        super(xczxSysUser,authorities);
        this.loginCode=loginCode;
        this.accessToken=accessToken;

    }

    public XczxUserLoginCodeAuthenticationToken(XczxSysUser xczxSysUser, String  loginCode) {
        super(xczxSysUser);
        this.loginCode=loginCode;

    }

    public XczxUserLoginCodeAuthenticationToken(String loginCode) {
        super(null);
        this.loginCode=loginCode;
    }


    @Override
    public String getLoginType() {
        return LoginTypeEnum.USER_TOKEN.getLoginType();
    }


    public static XczxUserLoginCodeAuthenticationToken unauthenticated(XczxSysUser xczxSysUser, String loginCode) {
        return new XczxUserLoginCodeAuthenticationToken(xczxSysUser,loginCode);
    }

    /**
     * This factory method can be safely used by any code that wishes to create a
     * authenticated <code>UsernamePasswordAuthenticationToken</code>.
     * @return UsernamePasswordAuthenticationToken with true isAuthenticated() result
     *
     * @since 5.7
     */
    public static XczxUserLoginCodeAuthenticationToken authenticated(XczxSysUser xczxSysUser, String loginCode,
                                                                     String accessToken,
                                                                     Collection<? extends GrantedAuthority> authorities) {
        return new XczxUserLoginCodeAuthenticationToken(xczxSysUser, loginCode,accessToken, authorities);
    }


    public String getLoginCode() {
        return loginCode;
    }

    public void setLoginCode(String loginCode) {
        this.loginCode = loginCode;
    }
}
